package com.zpark.config;

import com.zpark.filter.MyFilter02;
import com.zpark.listener.MyListener02;
import com.zpark.servlet.MyServlet02;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.Arrays;

/**
 * @author xiaoyu
 * @version 1.0 2022/10/8
 */
@Configuration
public class MyWebConfig {

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        return new ServletRegistrationBean(new MyServlet02(), "/ms02.do");
    }

    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        MyFilter02 myFilter02 = new MyFilter02();
        FilterRegistrationBean<Filter> filterFilterRegistrationBean = new FilterRegistrationBean<>(myFilter02);
        filterFilterRegistrationBean.setUrlPatterns(Arrays.asList("*.do"));
        return filterFilterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean servletListenerRegistrationBean() {
        return new ServletListenerRegistrationBean(new MyListener02());
    }
}
